package com.chexiaoy.lab.controller;

import com.chexiaoy.lab.domain.Driver;
import com.chexiaoy.lab.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by alickgeng on 16/8/11.
 */

@Controller
public class WelcomeController {
    @Autowired
    private DriverService driverService;

    @RequestMapping("/")
    public String welcome(ModelMap map) {
        map.addAttribute("name", "user");
        return "index";
    }

    @RequestMapping("/driver/{type}")
    public String getDriver(@PathVariable Integer type, ModelMap map) {
        List<Driver> drivers = this.driverService.sortDrivers(type);
        map.addAttribute("drivers", drivers);
        map.addAttribute("type", this.driverService.getTypeName());
        return "index";
    }

    @RequestMapping("/monitor")
    public String getResult(ModelMap map) {
        List<Driver> drivers = this.driverService.getSortedDrivers();
        map.addAttribute("drivers", drivers);
        map.addAttribute("type", this.driverService.getTypeName());
        return "monitor_o";
    }


}
